<template>
  <div class="item">
    <div>
      <div class="item-img">
        <img
          :alt="gdata.stock_info[idx].title"
          :src="gdata.stock_info[idx].image"
          style="opacity: 1"
        />
      </div>
      <h6>{{gdata.stock_info[idx].title}}</h6>
      <h3>{{gdata.stock_info[idx].sub_title}}</h3>
      <div class="params-colors">
        <ul class="colors-list">
          <li 
            v-for="(dot,dotidx) in gdata.stock_info" 
            :key="dotidx"
            @click="idx=dotidx"
          >
            <a :style="{background:dot.detail.color}" href="javascript:;" class="active">
            </a>
          </li>
        </ul>
      </div>
      <div class="item-btns clearfix">
        <span class="item-gray-btn">
          <router-link :to="`/detail/${gdata.id}`">查看详情</router-link>
        </span>
        <span class="item-blue-btn" @click="handleAdd">加入购物车 </span>
      </div>
      <div class="item-price clearfix">
        <i>¥</i>
        <span>{{gdata.stock_info[idx].price}}</span>
      </div>
      <div class="discount-icon">false</div>
      <div class="item-cover">
        <a href="javascript:;" target="_blank"></a>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props:['gdata'],
  data() {
    return {
      idx: 0 //标志激活的子商品下标
    }
  },
  methods: {
    handleAdd() {
      let {gdata,idx} = this
      this.$store.commit('cart/cartAddMut',gdata.stock_info[idx])
    }
  },
};
</script>

<style lang="less" scoped></style>
